<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/14/014
 * Time: 10:55
 */

namespace app\api\model;


use app\api\service\Token;

class MemberBank extends BaseModel {
    protected $hidden = ['create_time', 'update_time'];

    /**
     * 银行卡对应银行
     * @return \think\model\relation\belongsTo
     */
    public function bank() {
        return $this->belongsTo('Bank');
    }

    /**
     * 添加或者修改用户银行卡信息
     * @param $params
     * @param $id
     * @return bool
     */
    public static function createAndUpdateMemberBank($params, $id) {
        $uid = Token::getCurrentUid();

        $bank = self::get(['member_id' => $uid, 'id' => $id]);

        if ($bank) {
            $bank->save($params);
        } else {
            $params['member_id'] = $uid;
            self::create($params);
        }
        return true;
    }
}